﻿/// <reference path="_namespace.js" />



/*****************************************************************************
Ajax library class definition. Kevin Robinson 2006.
Class: ajax.lang.Formats
/*****************************************************************************/

ajax.lang.addNamespace("ajax.lang");

//-----------------------------------------------------------------------------
ajax.lang.Formats = function() // Constructor
{    
    ajax.lang.Formats.superConstructor.call(this);    
}

//-----------------------------------------------------------------------------
ajax.lang.extend("ajax.lang.Formats", "ajax.BaseObject"); // Inherit

//-----------------------------------------------------------------------------
ajax.lang.Formats.prototype.currency = function(num)
{
    return ajax.lang.Formats.currency(num);
}
//-----------------------------------------------------------------------------
ajax.lang.Formats.prototype.bytesToKilobytes = function(bytes)
{
    return ajax.lang.Formats.bytesToMegaBytes(bytes);
}


//-----------------------------------------------------------------------------
ajax.lang.Formats.prototype.toString = function()
{
    return "ajax.lang.Formats";
}

//-----------------------------------------------------------------------------
ajax.lang.Formats.cast = function(obj)
{///<returns type="ajax.lang.Formats"/>
    return obj;
}

//-----------------------------------------------------------------------------
// Statics
ajax.lang.Formats.currency = function(num)
{    
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '' + num + '.' + cents);
}

ajax.lang.Formats.bytesToKilobytes = function(bytes)
{
    return ajax.lang.Formats.currency(bytes/1024);
}

